package com.vhall.component.controller.goods;

import com.vhall.component.controller.goods.facade.LiveGoodsApiFacade;
import com.vhall.component.entity.goods.goods.*;
import com.vhall.component.entity.goods.vo.GetGoodsInfoResponseVO;
import com.vhall.component.entity.goods.vo.GuoxinPrdApiBindReqVO;
import com.vhall.component.entity.page.vo.PageVO;
import com.vhall.component.framework.common.annotation.VhallComponent;
import com.vhall.component.plugin.common.annotation.ApiSignatureAuth;
import com.vhall.component.plugin.common.annotation.VssTokenAuth;
import com.vhall.component.service.goods.GoodsApiService;
import com.vhall.component.service.goods.GoodsConsoleService;
import com.vhall.component.service.goods.LiveGoodsConsoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * @author guoxin.wang
 * @date 2021-10-26 10:15
 **/
@VhallComponent
public class LiveGoodsApiController implements LiveGoodsApiFacade {

    @Autowired
    private GoodsApiService goodsApiService;

    @Autowired
    private LiveGoodsConsoleService liveGoodsConsoleService;

    @Autowired
    private GoodsConsoleService goodsConsoleService;

    @ApiSignatureAuth
    @VssTokenAuth
    @Override
    public GoodsPage<GoodsApiBindListRspVO> getBindList(GoodsApiBindListReqVO reqVO) {
        LiveGoodsConsoleBindListReqVO param = new LiveGoodsConsoleBindListReqVO();
        BeanUtils.copyProperties(reqVO, param);
        param.setDefault();
        GoodsPage<LiveGoodsConsoleBindListRspVO> bindList = liveGoodsConsoleService.getBindList(param);
        if (bindList.getTotal() == 0) {
            return new GoodsPage<>(reqVO.getPage(), reqVO.getPageSize(), 0, new ArrayList<>(), bindList.getGoodsSwitch());
        }
        List<LiveGoodsConsoleBindListRspVO> data = bindList.getData();
        List<GoodsApiBindListRspVO> records = new ArrayList<>();
        GoodsApiBindListRspVO singleResult;
        for (LiveGoodsConsoleBindListRspVO single : data) {
            singleResult = new GoodsApiBindListRspVO();
            BeanUtils.copyProperties(single, singleResult);
            records.add(singleResult);
        }
        return new GoodsPage<>(reqVO.getPage(), reqVO.getPageSize(), bindList.getTotal(), records, bindList.getGoodsSwitch());
    }
    @VssTokenAuth
    @Override
    public PageVO<GetGoodsInfoResponseVO> getGuoxinPrdBindList(GuoxinPrdApiBindReqVO reqVO) {
        return liveGoodsConsoleService.getGuoxinPrdBindList(reqVO);
    }

    @ApiSignatureAuth
    @VssTokenAuth
    @Override
    public Boolean pushScreen(GoodsApiSendMessageReqVO reqVO) {
        return goodsApiService.pushScreen(reqVO);
    }

    @ApiSignatureAuth
    @VssTokenAuth
    @Override
    public Boolean setGoodsSwitch(GoodsApiSetGoodsSwitchReqVO reqVO) {
        return goodsApiService.setGoodsSwitch(reqVO);
    }

    @ApiSignatureAuth
    @VssTokenAuth
    @Override
    public GoodsRspVO get(GoodsDetailReqVO reqVO) {
        return goodsConsoleService.get(reqVO);
    }

}
